

import wsgiref.handlers

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from BeautifulSoup import BeautifulSoup
from xmw.tianya.bot import *

from xmw import tianya

from xmw import error
import os
import urllib2, urllib
import uuid

from google.appengine.ext import webapp



url = "http://cache.tianya.cn/techforum/content/516/39685.shtml"
url = "http://www.tianya.cn/techforum/content/516/72019.shtml"
class MainPage(xmw.RequestHandler):
    def get(self):
        if  not self.request.GET.has_key('post_id'):
            e = error.ARGUMENT_FAULT("URI:query_post needs parameter post_id.    /portal/query_post?post_id=XXXX")
            self.render_error(e)
            return
        
        post_id = self.request.GET['post_id']
        
        post_q=Post.all()
        post_q.filter('post_id =',post_id)
        post=post_q.get()
        
        if post is None:
            e   =error.POST_NOT_EXIST("post_id:%s"%post_id)
            self.render_error(e)
            return
        
        template_values = {
                               "post":post
                        }
        self.render_template(template_values, 'post')
        
        

def main():
    application = webapp.WSGIApplication(
                                       [('/portal/query_post', MainPage)],
                                       debug=True)
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()
